/**
 * FileName: Heap
 * Author:   powersi
 * Date:     2021/1/8 16:42
 * Description: heap
 */
package com.zm.demo.core.leetcode.heap;

/**
 * Description: heap
 * Author:      powersi
 * Date:        2021/1/8 16:42
 */
public class Heap {

    public int[]a; //数组，从1开始
    public int count; //已存储的数
    public int n; // 堆可以存储的最大数


    public Heap(int cap){
        a = new int[cap+1];
        n = cap;
        count = 0;
    }

    //插入
    public void insertMaxHeap(int data) {
        if (count >= n) return;
        count++;
        a[count] = data;
        int i = count;
        while (i/2 > 0 && a[i] > a[i/2]){
            swap(a, i, i/2);
            i = i/2;
        }

    }
    //插入
    public void insertMinHeap(int data) {
        if (count >= n) return;
        count++;
        a[count] = data;
        int i = count;
        while (i/2 > 0 && a[i] < a[i/2]){
            swap(a, i, i/2);
            i = i/2;
        }

    }

    private void swap(int[] a, int i, int i1) {
        int temp = a[i];
        a[i] = a[i/2];
        a[i/2] = temp;
    }

    //删除
    public void delete(int i) {
    }

    //排序
    public void sort(int i) {
    }
}
